
$(function () {

    //质检结果 1 合格（通过） 2 不合格（异常）
    function resultS(result) {
        if(result==1){
            return '通过'
        }else if(result==2){
            return '异常'
        }else{
            return ''
        }
    }
    //异常处理类型  1:设计缺陷  2：编程问题 3：零件报废 4：零件丢失 5：零件返工
    function unqunlityTypeS(unqunlityType) {
        if(unqunlityType==1){
            return '设计缺陷'
        }else if(unqunlityType==2){
            return '编程问题'
        }else if(unqunlityType==3){
            return '零件报废'
        }else if(unqunlityType==4){
            return '零件丢失'
        }else if(unqunlityType==5){
            return '零件返工'
        }else{
            return ''
        }
    }
    
    var url='/mes/zw/quality/detail';
    var mdObj=md5Fun(appUserId,url,appToken);
    var parameterObj= {
        "id":localStorage.historyId,
    };
    var parameter=Encrypt(JSON.stringify(parameterObj));
    console.log(Decrypt(parameter));
    $.ajax({
        type: "POST",
        timeout : 5000,
        url: webUrlCon+url,
        data:JSON.stringify(
            {"parameter":parameter}
        ),
        beforeSend: function(request) {
            request.setRequestHeader("Content-Type", "application/json");
            request.setRequestHeader("sequence", mdObj.sequence);
            request.setRequestHeader("nonceStr", mdObj.nonceStr);
            request.setRequestHeader("userId", appUserId);
            request.setRequestHeader("token",appToken);
            //xmlhttp.setRequestHeader("infName", url);
            //xmlhttp.setRequestHeader("osVersion", '');
            request.setRequestHeader("versionType", "1");
            request.setRequestHeader("osPlatform", mdObj.osPlatform);
            request.setRequestHeader("appVersion", mdObj.appVersion);
            request.setRequestHeader("sign", mdObj.sign);
        },
        success: function (data) {
            //layer.closeAll();
            $('.spinner').hide();
            $('.main').show();
            console.log(data);
            if(data.code==100){
                content=Decrypt(data.content);
                content=JSON.parse(content);
                console.log(content)
                var qualityHtml='<li>';
                if(sessionStorage.partType==4){
                    qualityHtml+='<div class="title">产品编号：'+content.productCode+'</div>';
                }else{
                    qualityHtml+='<div class="title">零件编号：'+content.partCode+'</div>';
                }
                qualityHtml+='<div class="content">';
                if(sessionStorage.partType==4){
                    qualityHtml+='<p><span>生产单数量：</span>'+content.productOrderNum+'</p>';
                    qualityHtml+='<p><span>产品监控编号：</span>'+content.monitorCode+'</p>';
                }else {
                    qualityHtml+='<p><span>零件名称：</span>'+content.partName+'</p>';
                    qualityHtml+='<p><span>零件监控编号：</span>'+content.monitorCode+'</p>';
                }
                qualityHtml+='<p><span>生产单号：</span>'+content.productionCode+'</p>'+
                    '<p><span>产品名称：</span>'+content.productName+'</p>' +
                    '<p><span>质检名称：</span>'+content.qualityName+'</p>' +
                    '<p><span>质检内容：</span>'+content.qualityContent+'</p>';
                    /*'<p><span>巡检频度：</span>'+content.inspectFrequency+'</p>' ;*/
                    /*'<p><span>良品率：</span>'+content.sufficeRate+'%</p>';*/

                if(content.img1!=''||content.img2!=''||content.img3!=''){
                    qualityHtml+='<div class="testImages">';
                    if(content.img1!=''){qualityHtml+= '<div class="img"><img onclick="zoomAlert(this)" src="'+ossUrl+content.img1+'"></div>';}
                    if(content.img2!=''){qualityHtml+= '<div class="img"><img onclick="zoomAlert(this)" src="'+ossUrl+content.img2+'"></div>';}
                    if(content.img3!=''){qualityHtml+= '<div class="img"><img onclick="zoomAlert(this)" src="'+ossUrl+content.img3+'"></div>';}
                    if(content.img4!=''&&content.img4!=undefined){qualityHtml+= '<div class="img"><img onclick="zoomAlert(this)" src="'+ossUrl+content.img4+'"></div>';}
                    qualityHtml+='</div>';
                }
                qualityHtml+='</div>' +
                    '<div class="content">' +
                    '<p><span>质检结果：</span>'+resultS(content.result)+'</p>' +
                    '<p><span>质检零件数量：</span>'+content.qualityCountTotal+'个</p>' +
                    '<p><span>不合格数量：</span>'+content.unQualityCountTotal+'个</p>';
                if(content.personLiableName!=''&&content.personLiableName!=undefined){qualityHtml+='<p><span>责任人：</span>'+content.personLiableName+'</p>';}
                qualityHtml+='<p><span>责任部门：</span>'+content.deptName+'</p>';
                if(content.unqunlityType>0){
                    qualityHtml+='<p><span>异常零件处理：</span>'+unqunlityTypeS(content.unqunlityType)+'</p>';
                }
                if(content.userName!=undefined){
                    qualityHtml+='<p><span>质检人：</span>'+content.userName+'</p>' ;
                }
                qualityHtml+='<p><span>质检时间：</span>'+content.hours+'小时（'+formatDateTime(content.startDate)+'-'+formatDateTime(content.finishDate)+'）</p>' +
                    '</div>' +
                    '</li>';
                if(content.extDetailScap!=undefined&&content.extDetailScap.length>0){  //废弃零件处理
                    qualityHtml+='<li>' +
                        '<div class="title">废弃零件处理</div>';
                    for(var i=0;i<content.extDetailScap.length;i++){
                        qualityHtml+='<div class="content"><p>负责人：'+content.extDetailScap[i].userName+'</p><p>数量：'+content.extDetailScap[i].count+'</p></div>';
                    }
                    qualityHtml+='</li>';
                }
                if(content.extDetailLose!=undefined&&content.extDetailLose.length>0){  //丢失零件处理
                    qualityHtml+='<li>' +
                        '<div class="title">丢失零件处理</div>';
                    for(var i=0;i<content.extDetailLose.length;i++){
                        qualityHtml+='<div class="content"><p>负责人：'+content.extDetailLose[i].userName+'</p><p>数量：'+content.extDetailLose[i].count+'</p></div>';
                    }
                    qualityHtml+='</li>';
                }
                if(content.extDetailRework!=undefined&&content.extDetailRework.length>0){  //返工零件处理
                    qualityHtml+='<li>' +
                        '<div class="title">返工零件处理</div>';
                    for(var i=0;i<content.extDetailRework.length;i++){
                        qualityHtml+='<div class="content"><p>负责人：'+content.extDetailRework[i].userName+'</p><p>数量：'+content.extDetailRework[i].count+'</p></div>';
                    }
                    qualityHtml+='</li>';
                }
                $('.TabMainUl').html(qualityHtml)
                $('.spinner').hide();
                $('.main').show();
            }else{
                $('.spinner').hide();
                layer.open({
                    content: data.code+' '+data.message
                    ,btn: '确定'
                });
            }
        },
        error: function(e) {
            //layer.closeAll();
            $('.spinner').hide();
            layer.open({
                content: '无法请求服务器，请稍后再试！'
                ,btn: '确定'
            });
        }
    });
})



lazyLoadInit({
    coverColor:"white",
    offsetBottom:0,
    offsetTopm:0,
    showTime:10,
    onLoadBackEnd:function(i,e){
        //console.log("onLoadBackEnd:"+i);
    }
    ,onLoadBackStart:function(i,e){
        //console.log("onLoadBackStart:"+i);
    }
});
